﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;


namespace GMS.Dinasty.Reporting
{
    public partial class billReport : DevExpress.XtraReports.UI.XtraReport
    {
        public billReport(string distirbutor, string customer,DataTable data, int VAT, string billNumber, string billDate)
        {
            InitializeComponent();
            xrTableCell20.Text = distirbutor;
            xrTableCell22.Text = customer;
            _vat = (decimal)VAT/100 + Math.Round(_vat,2);
            /*DataTable dt = new DataTable();
            dt = data.Clone();
            LoadTable(data, dt);*/
            LoadTable(data, dataSet1.Tables["billTable"]);
            xrLabel2.Text = billNumber;
            xrLabel4.Text = billDate;
           /* XRSummary summary = new XRSummary();
            summary.Running = SummaryRunning.Group;
            summary.FormatString = "{0:c2}";
            xrTableCell14.DataBindings.Add(new XRBinding("Text", dataSet1.Tables["billTable"], "summ"));
            xrTableCell14.Summary = summary;*/
        }
        decimal _vat = 1;
        private void LoadTable(DataTable sourceTable, DataTable destinationTable)
        {

            foreach (DataRow drw in sourceTable.Rows)
            {
                DataRow dr = destinationTable.NewRow();
                dr["order"] = drw["order"];
                dr["caption"] = drw["caption"];
                dr["units"] = drw["units"];
                dr["quantity"] = decimal.Parse(drw["quantity"].ToString());
                dr["lowprice"] = Math.Round(Math.Round(decimal.Parse(drw["lowprice"].ToString()), 2) / _vat, 2);
                dr["price"] = Math.Round(decimal.Parse(drw["lowprice"].ToString()),2);
                dr["summ"] = Math.Round(decimal.Parse(dr["quantity"].ToString()) * decimal.Parse(dr["lowprice"].ToString()),2);
                //dr["summvat"] = Math.Round(decimal.Parse(dr["quantity"].ToString()) * decimal.Parse(dr["price"].ToString()),2);
                dr["summvat"] = decimal.Parse(dr["summ"].ToString()) * _vat;
                dr["diff"] = decimal.Parse(dr["summvat"].ToString()) - decimal.Parse(dr["summ"].ToString());
                destinationTable.Rows.Add(dr);
            }
        }
    }
}
